package com.fangcang.service;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.springframework.core.task.TaskExecutor;
import org.springframework.stereotype.Service;

@Service("demoService")
public class DemoService {
	
//	private Logger log = LoggerFacFagetLogger(DemoService.class);
	
	@Resource(name="taskExecutor")
	private TaskExecutor testTaskExecutor;
	
	@Resource(name="threadPoolTaskScheduler")
	private TaskExecutor threadPoolTaskScheduler;

	public Map<String,String> getData() {
		
		Map<String, String> map = new HashMap<String, String>();
		map.put("name", "张三");
		map.put("id", "abc123");
		
//		for(int i=0;i<10;i++) {
//			try {
//				TimeUnit.SECONDS.sleep(5);
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
//		}
		
		for(int i=0; i<10; i++) {
			final int num = i;
			testTaskExecutor.execute(new Runnable() {
				@Override
				public void run() {
						try {
							TimeUnit.SECONDS.sleep(1);
							System.out.println(Thread.currentThread().getName() +  "： " + num +"}");
						} catch (InterruptedException e) {
							e.printStackTrace();
						}
					}
			});
		}
		
//		ScheduledExecutorTask scheduledTask = new ScheduledExecutorTask();
		threadPoolTaskScheduler.execute(new Runnable() {
			@Override
			public void run() {
				
			}
		});
		
		return map;
	}
}
